package cn.wwk.notification.user.controller;

import cn.wwk.notification.common.domain.User;
import cn.wwk.notification.common.dto.LoginFormDTO;
import cn.wwk.notification.common.result.Result;
import cn.wwk.notification.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author wwk
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 登录验证
     * */
    @PostMapping("/login")
    public Result<User> login(@RequestBody @Valid LoginFormDTO loginFormDTO) {

        return userService.login(loginFormDTO);
    }


    /**
     * 查询所有用户
     * */
    @GetMapping("/list")
    public Result<List<User>> getAll(){
        List<User> users = userService.list();
        return Result.success(users);
    }

    /**
     * 根据状态码查询用户
     * */
    @GetMapping("/get/status/{status}")
    public Result<List<User>> getUserByStatus(@PathVariable("status") int status){
        return userService.getUserByStatus(status);
    }
}
